﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using DiscoveryLogic.Analytics.DataObjects.Networks;
using DiscoveryLogic.Common.Utilities;

namespace DiscoveryLogic.Analytics.DataObjects
{
    public class EntityTypeUtil
    {
        public static Type GetType(EntityType entityType)
        {
            Type type = typeof (GrantDO);
            switch (entityType)
            {
                case EntityType.Grants:
                    type = typeof(GrantDO);
                    break;
                case EntityType.Organizations:
                    type = typeof(ExternalOrgDO);
                    break;
                case EntityType.Persons:
                    type = typeof(PersonDO);
                    break;
                case EntityType.Publications:
                    type = typeof(PublicationDO);
                    break;
                case EntityType.Document:
                    type = typeof (Document);
                    break;
                case EntityType.Subject:
                    type = typeof(Subject);
                    break;
                case EntityType.Cluster:
                    type = typeof (NetworkCluster);
                    break;
                case EntityType.Misc:
                    type = typeof (MiscEntity);
                    break;
            }
            return type;
        }

        public static EntityType GetEntityType(Type type)
        {
            EntityType entityType = EntityType.Grants;
            if (type == typeof(GrantDO))
                entityType = EntityType.Grants;
            else if (type == typeof(ExternalOrgDO))
                entityType = EntityType.Organizations;
            else if (type == typeof(PersonDO))
                entityType = EntityType.Persons;
            else if (type == typeof(PublicationDO))
                entityType = EntityType.Publications;
            else if (type == typeof(Document))
                entityType = EntityType.Document;
            else if (type == typeof(Subject))
                entityType = EntityType.Subject;
            else if (type==typeof(NetworkCluster))
                entityType = EntityType.Cluster;
            else if(type==typeof(MiscEntity))
                entityType = EntityType.Misc;
            return entityType;
        }

        public static PropertyInfo[] GetProperties(EntityType entityType)
        {
            PropertyInfo[] props = EntityTypeUtil.GetType(entityType).GetProperties();
            List<PropertyInfo> propList=new List<PropertyInfo>();
            foreach(PropertyInfo prop in props)
            {
                if(prop.CanWrite && prop.CanRead)
                {
                    if (prop.Name != "CollapsedID")
                    {
                        propList.Add(prop);
                    }
                }
            }
            
            return props;
        }

        public static string GetEntityDataSetFileExtension(EntityType entityType)
        {
            string extension = "";
            switch (entityType)
            {
                case EntityType.Publications:
                    extension = ".pubs";
                    break;
                case EntityType.Persons:
                    extension = ".persons";
                    break;
                case EntityType.Grants:
                    extension = ".grants";
                    break;
                case EntityType.Organizations:
                    extension = ".orgs";
                    break;
                case EntityType.Document:
                    extension = ".docs";
                    break;
                case EntityType.Subject:
                    extension = ".subjs";
                    break;
                case EntityType.Misc:
                    extension = ".misc";
                    break;
            }
            return extension;
        }
    }
}
